<?php

require_once '../funciones.php';
$con = con_caweb();
$id = explode("-pp-", $_REQUEST['id']);
$llave = $id[0];
$limit = $id[2];
switch ($id[1]) {
    case 's':
        $sql = "select a.interno,a.serial,a.sucursalcontrol,a.bodega,a.ubicacion,a.preciocompra from seriales a
                inner join seriales ser on ser.proveedor = a.proveedor and ser.factura = a.factura and ser.interno = '$llave' ORDER BY a.interno ASC ";
        break;
    case 'sp':
        $sql = "select a.interno,a.serial,a.sucursalcontrol,a.bodega,a.ubicacion,a.preciocompra from seriales_partes a
                inner join seriales_partes ser on ser.proveedor = a.proveedor and ser.factura = a.factura and ser.interno = '$llave' ORDER BY a.interno ASC limit 0,$limit";
        break;
    case 'det':
        $sql = "select tax.taxDesc as serial,a.sucursaldestino as sucursalcontrol,a.bodegadestino as bodega,a.ubicaciondestino as ubicacion,a.preciocompra from detalles a
                inner join intranetpccom.taxonomia tax on tax.codigotaxonomia = a.item
                where a.id ='$llave' ";
        break;
    default:
        break;
}
$result = mysql_query( $sql,$con ) or die("Couldn?t execute query.".mysql_error());

if ( stristr($_SERVER["HTTP_ACCEPT"],"application/xhtml+xml") ) {
		  header("Content-type: application/xhtml+xml;charset=utf-8"); 
} else {
		  header("Content-type: text/xml;charset=utf-8");
}
echo "<?xml version='1.0' encoding='utf-8'?>";
//echo "<sql>$sql</sql>";
echo "<rows>";
$numero=1;
while($row = mysql_fetch_array($result,MYSQL_ASSOC)) {
	echo "<row>";			
	echo "<cell>". $numero."</cell>";
	echo "<cell>".$row['serial'] ."</cell>"; //
	echo "<cell>". $row['sucursalcontrol']."</cell>";
	echo "<cell>". $row['bodega']."</cell>";
        if(strtoupper($row['bodega']) == 'CLI'){
            $sql = "select name from clientes where nit = '{$row['ubicacion']}'";
            $clie = mysql_query($sql,$con) or die("Error SQL ".mysql_error().$sql);
            echo "<cell>".utf8_encode(htmlspecialchars(mysql_result($clie, 0,"name"))) ."</cell>"; //
        } else echo "<cell>". $row['ubicacion']."</cell>";
        echo "<cell>". number_format($row['preciocompra'],2, ',', '.')."</cell>";
	echo "</row>";
    $numero=$numero+1;
}
echo "</rows>";				

?>